package rpg.core
{
	import flash.display.BitmapData;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	import rpg.Utils.GameUtils;
	import rpg.Utils.TextStyleUtil;
	import rpg.Utils.Val;
	import rpg.render.RenderData;
	import rpg.role.Hero;
	import rpg.role.SceneObject;

	public class NameComponent extends RenderComponent
	{
		/**
		 * 当前渲染的名字
		 */
		private var currName : String;

		private var txt : TextField;
		private var nameBmd : BitmapData;

		public function NameComponent(type : *)
		{
			super(type);
		}

		override public function notifyAdded() : void
		{
			super.notifyAdded();
			render.zIndex = Val.TOP;
			var textFormat : TextFormat = new TextFormat();
			textFormat.color = 0xffffff;
			textFormat.font = "宋体";
			textFormat.align = TextFormatAlign.CENTER;
			txt = new TextField();
			txt.filters = TextStyleUtil.blackFilters;
			txt.defaultTextFormat = textFormat;
			//render.addShow();
		}

		override public function updateRender(sceneX : int , sceneY : int , offsetX : int = 0 , offsetY : int = 0) : void
		{
			render.x = sceneX - txt.width / 2 - offsetX;
			render.y = sceneY - txt.height - offsetY - sceneObj.height;
			if(currName == sceneObj.name)
				return;
			currName = sceneObj.name;
			txt.text = currName;
			txt.height = txt.textHeight + 6;
			if(nameBmd)
				nameBmd.dispose();
			nameBmd = new BitmapData(txt.width , txt.height , true , 0);
			render.bitmapData = nameBmd;
			nameBmd.draw(txt);
		}
	}
}